﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Abp.Dependency;
using Abp.Domain.Entities;
using Abp.Domain.Repositories;
using Abp.Runtime.Caching;
using Hicap.AuthorizationServer.Core.Caches.Base.Interface;

namespace Hicap.AuthorizationServer.Core.Caches.Base
{
    public class CacheBase<TEntity, TCacheItem> : EntityCacheBase<TEntity, TCacheItem>, ITransientDependency, ICacheBase<TCacheItem>, ICacheExtend
    where TCacheItem : ICacheItemBase
    where TEntity : class, IEntity<int>
    {
        public CacheBase(ICacheManager cacheManager, IRepository<TEntity> repository)
            : base(cacheManager, repository)
        {
        }

        public override TCacheItem Get(int id)
        {
            var result = base.Get(id);
            return result;
        }

        public override Task<TCacheItem> GetAsync(int id)
        {
            var result = base.GetAsync(id);
            return result;
        }

        public List<TCacheItem> GetAll(params Expression<Func<IEntity, object>>[] propertySelectors)
        {
            return base.GetAll(propertySelectors);
        }

        public virtual Task<dynamic> GetExtend(int id)
        {
            dynamic result = Get(id);
            return Task.FromResult(result);
        }
    }
}